package com.example.helloword.excel.example;

import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Date;

/**
 * 单元格的测试
 */
public class Test2TypesofCells {
    public static void main(String[] args) throws IOException {
        XSSFWorkbook workbook = new XSSFWorkbook();
        XSSFSheet spreadsheet = workbook.createSheet("cell types");
        XSSFRow row = spreadsheet.createRow(2);
        row.createCell(0).setCellValue("Type of Cell");
        row.createCell(1).setCellValue("cell value");
        row = spreadsheet.createRow(3);
        row.createCell(0).setCellValue("set cell type BLANK");
        row.createCell(1);
        row = spreadsheet.createRow(4);
        row.createCell(0).setCellValue("sel cell type BOOLEAN");
        row.createCell(1).setCellValue(true);
        row = spreadsheet.createRow(5);
        row.createCell(0).setCellValue("set cell type ERROR");
        row.createCell(1).setCellValue(XSSFCell.CELL_TYPE_ERROR);
        row = spreadsheet.createRow(6);
        row.createCell(0).setCellValue("set cell type date");
        row.createCell(1).setCellValue(new Date());
        row = spreadsheet.createRow(7);
        row.createCell(0).setCellValue("set cell type numeric");
        row.createCell(1).setCellValue(20);
        row = spreadsheet.createRow(8);
        row.createCell(0).setCellValue("set cell type string");
        row.createCell(1).setCellValue("A String");
        FileOutputStream out = new FileOutputStream(new File("test2TypeOfCell.xlsx"));
        workbook.write(out);
        out.close();
        System.out.println("typesofcells.xlsx written successfully\"");
    }
}
